function Dwkhfx(){
	$(".chartregin").height(($(window).height()/3)-27);
	var width=$(window).width();
	$("#leftorg").width(width-20-width*0.75).height($(window).height()-50);
	this.form=this.InitEleUI();
	$("#year").val($("#hidyear").val());
	$("#month").val($("#hidmonth").val());
	$("#quarter").val($("#hidquarter").val());
	this.form.render('select');
	
	this.InitOrg();
	//InitChart();
	this.GetStatisData();
	this.GetStatisDwData();
	this.GetStatisYearDw();

}



Dwkhfx.prototype.InitEleUI=function(){
	var form;
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       
       form.on('select(year)', function (data) {  
    	   $("#hidyear").val(data.value);
           vDwkhfx.GetStatisData();
       }); 
       
       form.on('select(month)', function (data) {  
    	   $("#hidmonth").val(data.value);  
    	   vDwkhfx.GetStatisData();
       });

        form.on('select(quarter)', function (data) {
            $("#hidquarter").val(data.value);
            vDwkhfx.GetStatisData();
        });

        form.on('select(type)', function (data) {
            if (data.value == 'y') {
                $('.month').hide();
                $('.quarter').hide();

            } else if (data.value == 'm') {
                $('.month').show();
                $('.quarter').hide();
            } else {
                $('.month').hide();
                $('.quarter').show();
            }
            vDwkhfx.GetStatisData();
        })


	   form.render();
	});  
	return form;
}

Dwkhfx.prototype.InitOrg = function() {
	var comboboxm=$("#orgid").ligerComboBox({
		valueField : 'orgid',
		textField : 'orgname',
		selectBoxWidth : 250,
		selectBoxHeight:250,
		treeLeafOnly:false,
		valueFieldID:"hid",
		tree: {url : '../common/get_org_list?orgtype=0',
			checkbox: false, 
			nodeWidth:150,
			ajaxType: 'get', 
			idFieldName: 'orgid',
			textFieldName:"orgname",
			idField:"orgid",
        	parentIDField:"orgparentid"
		},
		onSelected : function(orgid, orgname) {// id为空值，name为选择的值
			$("#hidszdw").val(orgid);
			$("#hidorgname").val(orgname);
			vDwkhfx.GetStatisDwData();
			vDwkhfx.GetStatisYearDw();
		},
		width : 250
	});
	return comboboxm;
}

Dwkhfx.prototype.GetStatisData=function(){
	$("#orgname").html($("#hidorgname").val());
	$.ajax({
		type:"GET",
		url:"getdwkhdata",
		data:{year:$("#hidyear").val(),month:$("#hidmonth").val(),quarter:$("#hidquarter").val(),type:$("#type").val(),szdw:$("#hidszdw").val()},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				if(data.items.znmap){
					var znobject=data.items.znmap;
					var orgdata=[];
					var scoreata=[];
					var minvalue=0.000;
					var maxvalue=0.000;
					for(i=0;i<znobject.length;i++){
						orgdata.push(znobject[i].orgname);
						if(Number(znobject[i].score.toFixed(3))>maxvalue){
							maxvalue=znobject[i].score.toFixed(3);
						}
						if(i==0){
							minvalue=znobject[i].score.toFixed(3);
						}
						else{
							if(Number(znobject[i].score.toFixed(3))<minvalue){
							minvalue=znobject[i].score.toFixed(3);
						    }
						}


						scoreata.push(znobject[i].score.toFixed(3));
					}
					InitChats(orgdata,scoreata,minvalue,maxvalue);
				}
				
				if(data.items.pcsmap){
					var pcsobject=data.items.pcsmap;
					var orgdata=[];
					var scoreata=[];
					var minvalue=0.000;
					var maxvalue=0.000;
					for(i=0;i<pcsobject.length;i++){
						orgdata.push(pcsobject[i].orgname.replace('派出所',''));
						if(Number(pcsobject[i].score.toFixed(3))>maxvalue){
							maxvalue=pcsobject[i].score.toFixed(3);
						}
						if(i==0){
							minvalue=pcsobject[i].score.toFixed(3);
						}
						else{
							if(Number(pcsobject[i].score.toFixed(3))<minvalue){
							minvalue=pcsobject[i].score.toFixed(3);
						    }
						}
						scoreata.push(pcsobject[i].score.toFixed(3));
					}
					InitChatsPcs(orgdata,scoreata,minvalue,maxvalue);
				}
				
				if(data.items.jczmap){
					var jczobject=data.items.jczmap;
					var orgdata=[];
					var scoreata=[];
					var minvalue=0.000;
					var maxvalue=0.000;
					for(i=0;i<jczobject.length;i++){
						orgdata.push(jczobject[i].orgname.replace('派出所',''));
						if(Number(jczobject[i].score.toFixed(3))>maxvalue){
							maxvalue=jczobject[i].score.toFixed(3);
						}
						if(i==0){
							minvalue=jczobject[i].score.toFixed(3);
						}
						else{
							if(Number(jczobject[i].score.toFixed(3))<minvalue){
							minvalue=jczobject[i].score.toFixed(3);
						    }
						}
						scoreata.push(jczobject[i].score.toFixed(3));
					}
					InitChatsJcz(orgdata,scoreata,minvalue,maxvalue);
				}
				
				
				
				
			}
		}
	})
}

Dwkhfx.prototype.Rehref =function(){
    window.location.href="../teamass/buns_kp_look";
}

Dwkhfx.prototype.GetStatisDwData=function(){
	$("#orgname").html($("#hidorgname").val());
	$.ajax({
		type:"GET",
		url:"getdwkhdatadw",
		data:{year:$("#hidyear").val(),month:$("#hidmonth").val(),szdw:$("#hidszdw").val()},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				if(data.items.dwmap){
					//alert(data);
					var dwobject=data.items.dwmap;
					var ymdata=[1,2,3,4,5,6,7,8,9,10,11,12];
					var dwobject=data.items.dwmap;
					var yeardata=[];
					var minvalue=0.000;
					var maxvalue=0.000;
					for(l=0;l<ymdata.length;l++){
						var mvalue=0;
						if(dwobject.length>0){
							for(k=0;k<dwobject.length;k++){
								if(dwobject[k].monthstr==ymdata[l]){
									mvalue=dwobject[k].score.toFixed(3);
									if(Number(dwobject[k].score.toFixed(3))>maxvalue){
							maxvalue=dwobject[k].score.toFixed(3);
						}
						if(l==0){
							minvalue=dwobject[k].score.toFixed(3);
						}
						else{
							if(Number(dwobject[k].score.toFixed(3))<minvalue){
							minvalue=dwobject[k].score.toFixed(3);
						    }
						}
								}
							}
						}
						yeardata.push(mvalue);
					}
					InitChatsOrg(yeardata,minvalue,maxvalue);
				}
				
				
			}
		}
	})
}


Dwkhfx.prototype.GetStatisYearDw=function(){
	$("#orgnameyear").html($("#hidorgname").val());
	$.ajax({
		type:"GET",
		url:"getdwkhyeardw",
		data:{szdw:$("#hidszdw").val()},
		beforeSend:function(XHR){

		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
					if(data.items.dwmapdw){
						var ymdata=[2015,2016,2017,2018,2019,2020,2021,2022];
						var ywbject=data.items.dwmapdw;
						var scoreata=[];
						var maxindex=0;
						for(l=0;l<ymdata.length;l++){
							var mvalue=-1;
							if(ywbject.length>0){
								for(k=0;k<ywbject.length;k++){
									if(ywbject[k].yearstr==ymdata[l]){
										mvalue=ywbject[k].rank;
										if(maxindex<mvalue){
											maxindex=mvalue;
										}
									}
								}
							}
							if(mvalue==-1){
								scoreata.push('');
							}
							else{
								scoreata.push(mvalue);
							}

						}
						InitChatsOrgYear(scoreata,maxindex);
					}
				}
			}
	})
}

var vDwkhfx;
$(function () {
	vDwkhfx = new Dwkhfx();
})



function InitChats(orgdata,scoredata,minvalue,maxvalue){
	$("#Chart").width($(window).width()*0.7);
	$("#Chart").height(($(window).height()/3)-10);
	var myChart = echarts.init(document.getElementById('Chart'));
	 var index=1;
	option = {
		    tooltip: {
		        trigger: 'axis',
		        axisPointer: {
		           // type: 'shadow'
		        },
		        backgroundColor:'#3187c2'
		        //,formatter:'{b0} {c}人'
		        	,formatter: function(params) {
	                    var result = '';
	                   
	                    params.forEach(function (item,i) {
	                    	//alert(JSON.stringify(item))
	                        //result += "   "+item.marker +item.name+"：     "+ item.value +" ";
	                    	result += "第 "+(orgdata.indexOf(item.name)+1)+" 名：     "+ item.value +" 分";
	                    	index++;
	                    });
	                    return result;
	                },
	                textStyle: {
			              fontWeight: "normal",
			              color: "#aadeff", 
			              fontSize: 8
			        }
		    },
		    grid:{
                x:40,
                y:50,
                x2:35,
                y2:50,
               
                borderWidth:1
            },
		    toolbox: {
		        show: true,
		        feature: {
		            //saveAsImage: {}
		        }
		    },
		    xAxis:  {
		        type: 'category',
		        boundaryGap: true,
		        data: orgdata,
		        axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    },
                    interval:0
                    ,rotate:340
                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    }
		    },
		    yAxis: {
		        type: 'value',
		        show: true,
		        axisLabel: {
		            formatter: '{value}',
		            color: '#61a6e7'
		        },
		        axisPointer: {
		            snap: true
		        },
		        splitLine: {           // 分隔线
			        show: true,        // 默认显示，属性show控制显示与否
			        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
			            color: ['#2180c5'],
			            width: 1,
			            type: 'solid'
			        }
			    },
			    splitArea: {           // 分隔区域
			        show: true,       // 默认不显示，属性show控制显示与否
			        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
			            color: ['#25619f','none']
			        }
			    },
			    axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    },
			    //min:0,
		       // max:100,
				 //minInterval:0.1
				min:(minvalue-0.1).toFixed(3),
					max:maxvalue,
		        minInterval:0.1
		    },
		    

		    series: [
		        {
		            name:'年',
		            type:'bar',
		            smooth: true,
		            itemStyle : {  
                        normal : {  
                        	 color: new echarts.graphic.LinearGradient(
                                     0, 0, 0, 1,
                                   [
                                       {offset: 0, color: '#3899ff'},   // {offset: 0, color: '#2FDE80'},   
                                       {offset: 1, color: '#71effd'}//  {offset: 1, color: '#2FDECA'}
                                   ])
  
                        }  
                    }, 
                    barWidth : 30,
		            data: scoredata
		        }
		    ]
		};
	 myChart.setOption(option);
	
}


function InitChatsPcs(orgdata,scoredata,minvalue,maxvalue){
	$("#ChartPcs").width($(window).width()*0.7);
	$("#ChartPcs").height(($(window).height()/3)-10);
	var myChart = echarts.init(document.getElementById('ChartPcs'));
	 var index=1;
	option = {
		    tooltip: {
		        trigger: 'axis',
		        axisPointer: {
		           // type: 'shadow'
		        },
		        backgroundColor:'#3187c2'
		        //,formatter:'{b0} {c}人'
		        	,formatter: function(params) {
	                    var result = '';
	                   
	                    params.forEach(function (item,i) {
	                    	//alert(JSON.stringify(item))
	                        //result += "   "+item.marker +item.name+"：     "+ item.value +" ";
	                    	result += "第 "+(orgdata.indexOf(item.name)+1)+" 名：     "+ item.value +" 分";
	                    	index++;
	                    });
	                    return result;
	                },
	                textStyle: {
			              fontWeight: "normal",
			              color: "#aadeff", 
			              fontSize: 8
			        }
		    },
		    grid:{
                x:40,
                y:50,
                x2:35,
                y2:50,
               
                borderWidth:1
            },
		    toolbox: {
		        show: true,
		        feature: {
		            //saveAsImage: {}
		        }
		    },
		    xAxis:  {
		        type: 'category',
		        boundaryGap: true,
		        data: orgdata,
		        axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    },
                    interval:0
                    ,rotate:310
                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    }
		    },
		    yAxis: {
		        type: 'value',
		        show: true,
		        axisLabel: {
		            formatter: '{value}',
		            color: '#61a6e7'
		        },
		        axisPointer: {
		            snap: true
		        },
		        splitLine: {           // 分隔线
			        show: true,        // 默认显示，属性show控制显示与否
			        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
			            color: ['#2180c5'],
			            width: 1,
			            type: 'solid'
			        }
			    },
			    splitArea: {           // 分隔区域
			        show: true,       // 默认不显示，属性show控制显示与否
			        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
			            color: ['#25619f','none']
			        }
			    },
			    axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    },
			   // min:0,
		       // max:100,
		       // minInterval:50
			   	min:(minvalue-0.1).toFixed(3),
					max:maxvalue,
		        minInterval:0.1
		    },
		    

		    series: [
		        {
		            name:'年',
		            type:'bar',
		            smooth: true,
		            itemStyle : {  
                        normal : {  
                        	 color: new echarts.graphic.LinearGradient(
                                     0, 0, 0, 1,
                                   [
                                       {offset: 0, color: '#fece9d'},   // {offset: 0, color: '#2FDE80'},   
                                       {offset: 1, color: '#ff8f8b'}//  {offset: 1, color: '#2FDECA'}
                                   ])
  
                        }  
                    }, 
                    barWidth : 20,
		            data: scoredata
		        }
		    ]
		};
	 myChart.setOption(option);
	
}


function InitChatsJcz(orgdata,scoredata,minvalue,maxvalue){
	$("#ChartJcz").width($(window).width()*0.7);
	$("#ChartJcz").height(($(window).height()/3)-10);
	var myChart = echarts.init(document.getElementById('ChartJcz'));
	 var index=1;
	option = {
		    tooltip: {
		        trigger: 'axis',
		        axisPointer: {
		           // type: 'shadow'
		        },
		        backgroundColor:'#3187c2'
		        //,formatter:'{b0} {c}人'
		        	,formatter: function(params) {
	                    var result = '';
	                   
	                    params.forEach(function (item,i) {
	                    	//alert(JSON.stringify(item))
	                        //result += "   "+item.marker +item.name+"：     "+ item.value +" ";
	                    	result += "第 "+(orgdata.indexOf(item.name)+1)+" 名：     "+ item.value +" 分";
	                    	index++;
	                    });
	                    return result;
	                },
	                textStyle: {
			              fontWeight: "normal",
			              color: "#aadeff", 
			              fontSize: 8
			        }
		    },
		    grid:{
                x:40,
                y:50,
                x2:35,
                y2:50,
               
                borderWidth:1
            },
		    toolbox: {
		        show: true,
		        feature: {
		            //saveAsImage: {}
		        }
		    },
		    xAxis:  {
		        type: 'category',
		        boundaryGap: true,
		        data: orgdata,
		        axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    }
                    ,interval:0
                    //,rotate:310
                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    }
		    },
		    yAxis: {
		        type: 'value',
		        show: true,
		        axisLabel: {
		            formatter: '{value}',
		            color: '#61a6e7'
		        },
		        axisPointer: {
		            snap: true
		        },
		        splitLine: {           // 分隔线
			        show: true,        // 默认显示，属性show控制显示与否
			        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
			            color: ['#2180c5'],
			            width: 1,
			            type: 'solid'
			        }
			    },
			    splitArea: {           // 分隔区域
			        show: true,       // 默认不显示，属性show控制显示与否
			        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
			            color: ['#25619f','none']
			        }
			    },
			    axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    },
			   // min:0,
		        //max:100,
		        //minInterval:50
			   	min:(minvalue-0.1).toFixed(3),
					max:maxvalue,
		        minInterval:0.1
		    },
		    

		    series: [
		        {
		            name:'年',
		            type:'bar',
		            smooth: true,
		            itemStyle : {  
                        normal : {  
                        	 color: new echarts.graphic.LinearGradient(
                                     0, 0, 0, 1,
                                   [
                                       {offset: 0, color: '#fece9d'},   // {offset: 0, color: '#2FDE80'},   
                                       {offset: 1, color: '#ff8f8b'}//  {offset: 1, color: '#2FDECA'}
                                   ])
  
                        }  
                    }, 
                    barWidth : 20,
		            data: scoredata
		        }
		    ]
		};
	 myChart.setOption(option);
	
}


function InitChatsOrg(yeardata,minvalue,maxvalue){
	// alert(minvalue+" "+maxvalue);
	//$("#ChartOrg").width($(window).width()-30);
	//$("#ChartOrg").height(($(window).height()));
	$("#ChartOrg").height(($(window).height()/2-10));
	var myChart = echarts.init(document.getElementById('ChartOrg'));
	option = {
			 tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        }
			    },
		    xAxis: {
		    	type: 'value'
		        ,axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    }
                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    },
			    splitLine: {           // 分隔线
			        show: true,        // 默认显示，属性show控制显示与否
			        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
			            color: ['#4170a8'],
			            width: 1,
			            type: 'solid'
			        }
			    },
			    splitArea: {           // 分隔区域
			        show: true,       // 默认不显示，属性show控制显示与否
			        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
			            color: ['#305d94','none']
			        }
			    },
			    //min:0,
		       // max:100,
		        //minInterval:25
					min:(minvalue-0.1).toFixed(3),
					max:maxvalue,
		        minInterval:0.1
		       
		    },
		    yAxis: {
		    	 type: 'category',
			        boundaryGap: false,
			        data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
			        axisLabel: {
	                    show: true,
	                    textStyle: {
	                        color: '#aadeff'
	                    }
	                },
	                axisTick:{
				    	show:false
				    },
				    axisLine:{
				    	show:false
				    }
		    },
		    grid: {
		        left: 10,
		        right: 20,
		        bottom: 35,
		        x:0,
		        y:40,
		        y2:0,
		        containLabel: true
		    },
		    series: [{
		        data: yeardata,
		        type: 'line',
		        itemStyle : {  
                    normal : {  
                    	 color:'#00FF00',  
                         lineStyle:{  
                             color:'#825c8b'  
                         }    
                    }  
                },
                symbolSize: 8,//拐点大小
		        areaStyle: { normal : {  
		                        	 color: new echarts.graphic.LinearGradient(
		                                     0, 0, 0, 1,
		                                   [
		                                      {offset: 0, color: 'rgba(38,98,160,0.3)'},   // {offset: 0, color: '#2FDE80'},   
		                                      {offset: 1, color: 'rgba(250,250,250,0.3)'}//  {offset: 1, color: '#2FDECA'}
		                                      
		                                   ])
		  
		                        } 
		                        }
		    }]
		};
	
	
	
	

	
	myChart.setOption(option);
}





function InitChatsOrgYear(yeardata,maxindex){
	//$("#ChartOrgYear").width($(window).width()/2-10);
	$("#ChartOrgYear").height(($(window).height()/2-40));
	var myChart = echarts.init(document.getElementById('ChartOrgYear'));
	option = {
			 tooltip : {
			        trigger: 'axis',
			        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			        },
			        backgroundColor:'#3187c2',
			        textStyle: {
			              fontWeight: "normal",
			              color: "#aadeff",
			              fontSize: 8
			        },
			        formatter: function(params) {
	                    var result = '';
	                    params.forEach(function (item) {
	                    	//alert(JSON.stringify(item))
	                    	if(item.value>0){
	                    		result += "   "+item.marker +item.name+"年：     第 "+ item.value +" 名";
	                    	}

	                    });
	                    return result;
	                }

			    },



		    xAxis: { type: 'category',
		        boundaryGap: false,
		        data: ['2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022'],
		        axisLabel: {
                    show: true,
                    textStyle: {
                        color: '#aadeff'
                    },
                    interval:0,
                    rotate:310

                },
                axisTick:{
			    	show:false
			    },
			    axisLine:{
			    	show:false
			    }



		    },
		    yAxis: {
		    	inverse:true,
		    	type: 'value'
			        ,axisLabel: {
	                    show: true,
	                    textStyle: {
	                        color: '#aadeff'
	                    }
	                },
	                axisTick:{
				    	show:false
				    },
				    axisLine:{
				    	show:false,
				    	onZero: false
				    },
				    splitLine: {           // 分隔线
				        show: true,        // 默认显示，属性show控制显示与否
				        lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
				            color: ['#4170a8'],
				            width: 1,
				            type: 'solid'
				        }
				    },
				    splitArea: {           // 分隔区域
				        show: true,       // 默认不显示，属性show控制显示与否
				        areaStyle: {       // 属性areaStyle（详见areaStyle）控制区域样式
				            color: ['#305d94','none']
				        }
				    },
				    min:1,
			        max:(maxindex+1)%2==0?(maxindex+1):(maxindex+2)
			        ,minInterval:1
		    },
		    grid: {
		        left: 10,
		        right: 20,
		        bottom: 10,
		        x:0,
		       // y:10,
		        x2:0,
		        y2:20,
		        containLabel: true
		    },
		    series: [{
		        data: yeardata,
		        type: 'line'
		        ,itemStyle : {
                    normal : {
                    	 color:'#00FF00',
                    	 borderColor:'red',
                         lineStyle:{
                             color:'#825c8b',
                             width:4
                         }

                    }
                },
                symbolSize: 12//拐点大小

		    }]
		};
	myChart.setOption(option);
}
